﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using WebService.VO;

namespace WebService.DAO
{
    public class UserCommentDAO
    {
        private dbConnection conn;
        /// <summary>
        /// khởi tạo đối tượng xử lý dl
        /// </summary>
        public UserCommentDAO()
        {
            conn = new dbConnection();
        }

        /// <summary>
        /// Get Comment by Item
        /// </summary>
        /// <param name="itemID"></param>
        /// <returns></returns>
        public DataTable getCommentByItem(int itemID)
        {
            return conn.GetDataTable("Select [UserName], [Comment], [Time] from [tbl_UserComment] a, [tbl_Device] b where a.[DeviceID]=b.[ID] and [ItemID]=" + itemID);
        }

        /// <summary>
        /// Insert Comment
        /// </summary>
        /// <param name="comment"></param>
        public void insertComment(UserCommentVO comment)
        {
            string sqlInsert = "INSERT INTO tbl_UserComment VALUES(@ItemID, @DeviceID, @Time, @Comment)";

            IDictionary<string, string> d = new Dictionary<string, string>();

            d.Add("@ItemID", comment.Item.ItemId.ToString());
            d.Add("@DeviceID", comment.Device.Id.ToString());
            d.Add("@Time", comment.Time.ToString("hh:mm:ss MM/dd/yyyy"));
            d.Add("@Comment", comment.Comment);

            conn.ExecuteQuery(sqlInsert, d, false);
        }

    }
}